﻿using System;
using System.Collections.Generic;
using System.Data;
using Loki.Data;
using Luna.Data.Configuration;

namespace Luna.Data.CRM
{
    /// <summary>
    /// Mapper for data interface ICategoryData.
    /// </summary>
    public partial class CategoryDataMapper : LunaEntityMapper<CategoryData, ICategoryData> 
    {
        public CategoryDataMapper()
        {
            GetAllRequest = "Crm.category_select_all";
            GetRequest = "Crm.category_select";
            InsertRequest = "Crm.category_insert";
            UpdateRequest = "Crm.category_update";
            DeleteRequest = "Crm.category_delete";
        }
        
        private const string NameColumnName = "Name";
        private const string DescriptionColumnName = "Description";
        private const string ColorColumnName = "Color";

        protected override void LoadCoreData(ICategoryData entity, IDataRecord record)
        {
            entity.Name = record.GetString(NameColumnName);
            entity.Description = record.GetString(DescriptionColumnName);
            entity.Color = record.GetString(ColorColumnName);
        }
        
        protected override void MapSaveParameters(IDatabaseCommand command, ICategoryData entity)
        {
            command.AddParameter(NameColumnName, entity.Name);
            command.AddParameter(DescriptionColumnName, entity.Description);
            command.AddParameter(ColorColumnName, entity.Color);
            command.AddParameter(IDParameterName, entity.PK);
        }
           
    }
}